// 注册页面
<template>
  <div class="login-container">
    <div class="login-box">
      <h2>博客后台注册</h2>
      <form @submit.prevent="handleReg()">
        <div class="form-group">
          <label>用户名</label>
          <input type="text" v-model="username" required />
        </div>
        <div class="form-group">
          <label>密码</label>
          <input type="password" v-model="password" required />
        </div>
        <button type="submit">注册</button>
      </form>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "RegPage",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    // 登录函数
    handleReg() {
      const username = this.username;
      const password = this.password;
      console.log(username, password);
      // this.$message.success("登录功能需对接新API");
      axios
        .post("http://127.0.0.1:3000/api/reg", { username, password })
        .then((data) => {
          // console.log(data);
          if (data.data.data) {
            this.$message.success("注册成功");
            // console.log(data.data.data);
            // localStorage.setItem("token", data.data.data); // 存 token
            this.$router.push("/login");
          } else {
            this.$message.error("注册失败，请检查后端服务");
          }
        })
        .catch(() => {
          this.$message.error("注册信息无效");
        });
    },
  },
};
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

.login-box {
  width: 380px;
  padding: 40px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
  text-align: center;
}

h2 {
  margin-bottom: 30px;
  color: #333;
  font-weight: 500;
}

.form-group {
  margin-bottom: 25px;
  text-align: left;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: #555;
  font-size: 14px;
}

.form-group input {
  width: 100%;
  padding: 12px 15px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.3s;
}

.form-group input:focus {
  border-color: #409eff;
  outline: none;
}

button {
  width: 100%;
  padding: 12px;
  background: linear-gradient(to right, #409eff, #64b5f6);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}
</style>